package com.ssm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.entity.Student;
import com.ssm.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * Created by Lenovo on 2019-4-21.
 */
@Controller
@RequestMapping("/Student")
@SessionAttributes("student")
public class StudentController {
        @Autowired
        private StudentService studentServiceImpl;
       @RequestMapping("list.do")
       public String list(@RequestParam(value="page",defaultValue= "1") int page,Model model){
           //定义第几页和每页显示的记录数
           PageHelper.startPage(page,5);
           //调用studentServiceImpl的list方法，从数据库取数据
           List<Student> students=studentServiceImpl.list();
          //通过model对象带出分页封装的students数据pageInfo，到listStudent.jsp页面
            PageInfo pageInfo=new PageInfo(students);
           model.addAttribute("pageInfo",pageInfo);
        return "listStudents";
    }

}
